package com.mvu.banana.tools;

import com.mvu.banana.domain.server.BuilderGenerator;
import com.mvu.banana.guest.client.LoginPanel;
import com.mvu.banana.guest.client.SignUpForm;
import com.mvu.banana.guest.client.UserTile;
import com.mvu.banana.internal.client.RunBox;
import com.mvu.banana.user.client.SearchProfile;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;

import java.io.File;
import java.io.FilenameFilter;

/**
 * Interface description...
 *
 * @author mvu
 */
public class CodeGenerator {
  protected static Logger logger = Logger.getLogger(CodeGenerator.class);
  static final Class[] composites = new Class[]{
          LoginPanel.class, SignUpForm.class, UserTile.class, RunBox.class,
          SearchProfile.class
  };

  public static void main(String[] args) throws Exception {
    File serverFolder = new File("src/main/java/com/mvu/banana/domain/server");
    FilenameFilter filenameFilter = new FilenameFilter() {
      @Override
      public boolean accept(File file, String s) {
        return s.endsWith("Def.java");
      }
    };
    logger.setLevel(Level.ERROR);
    for (File file : serverFolder.listFiles(filenameFilter)) {
      String fileName = file.getName();
      String className = fileName.substring(0, fileName.length()-5);
      Class<?> defClass = Class.forName("com.mvu.banana.domain.server." + className);
      BuilderGenerator.genBuilder(defClass);
    }
    for(Class c : composites){
      DtoGenerator.genDto(c);
    }
    ClientTestGenerator.genTest(composites);
  }

}
